package com.lmj.learnspringboot.interceptor;

import com.lmj.learnspringboot.annotation.MethodParam;
import com.lmj.learnspringboot.enums.ResultCode;
import com.lmj.learnspringboot.model.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

import java.lang.reflect.Method;
import java.lang.reflect.Parameter;

/**
 * MethodParam注解拦截器
 *
 * @author: lmj
 * @version: MethodParamInterceptor.java lmj v1.0 2021/11/14 00:42
 */
@Slf4j
public class MethodParamInterceptor implements MethodInterceptor {

    @Override
    public Object invoke(MethodInvocation methodInvocation) throws Throwable {
        Object proceed = null;
        try {
            proceed = methodInvocation.proceed();
        } catch (Exception e) {
            return Result.fail(ResultCode.API_EXCEPTION);
        }
        return proceed;
    }
}
